package com.sgcc.ln.pmos.e_ln_mall.adapter;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.ln.pmos.common.bean.PowMonth;
import com.sgcc.pmos.nativesdk.R;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class PowersetAdapter extends BaseQuickAdapter<PowMonth, BaseViewHolder> {
    private String year;
    private int width = 0;
    private Map<Integer,String> total=new HashMap<>();

    public PowersetAdapter() {
        super(R.layout.item_powerset);
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    public void setYear(String year) {
        this.year = year;
    }

    public void setItemWidth(int width) {
        this.width = width;
    }

    public interface OnItemClickListener {
        //条目点击
        void OnItemsClickListener(int position, String s);
        //条目点击
        void OnTotalClickListener();

    }

    private OnItemClickListener mOnItemClickListener;

    public void setItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }
    private String convertDoubleToString(String num) {
        BigDecimal bd = new BigDecimal(num);
        return bd.stripTrailingZeros().toPlainString();

    }
    public Map<Integer,String>  getTotal(){
        return total;
    }
    @Override
    protected void convert(BaseViewHolder baseViewHolder, PowMonth s) {
        String totalStr=gettotalPowNum(s);
        total.put(s.getMonthDate(),totalStr);
        baseViewHolder.setText(R.id.total_pow_txt,totalStr);
        if (width != 0) {
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((int) (width),
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            ((LinearLayout) baseViewHolder.getView(R.id.root_linner)).setLayoutParams(lp);
        }
        baseViewHolder.getView(R.id.liner_total).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mOnItemClickListener!=null){
                    mOnItemClickListener.OnTotalClickListener();
                }

            }
        });


        baseViewHolder.setText(R.id.time_txt, year + "-" + s.getMonthDate());
        baseViewHolder.setText(R.id.edit_1, TextUtils.isEmpty(s.getREnergy1()) ? "" : s.getREnergy1());
        baseViewHolder.setText(R.id.edit_2, TextUtils.isEmpty(s.getREnergy2()) ? "" : s.getREnergy2());
        baseViewHolder.setText(R.id.edit_3, TextUtils.isEmpty(s.getREnergy3()) ? "" : s.getREnergy3());
        baseViewHolder.setText(R.id.edit_4, TextUtils.isEmpty(s.getREnergy4()) ? "" : s.getREnergy4());
        baseViewHolder.setText(R.id.edit_5, TextUtils.isEmpty(s.getREnergy5()) ? "" : s.getREnergy5());
        baseViewHolder.setText(R.id.edit_6, TextUtils.isEmpty(s.getREnergy6()) ? "" : s.getREnergy6());
        baseViewHolder.setText(R.id.edit_7, TextUtils.isEmpty(s.getREnergy7()) ? "" : s.getREnergy7());
        baseViewHolder.setText(R.id.edit_8, TextUtils.isEmpty(s.getREnergy8()) ? "" : s.getREnergy8());
        baseViewHolder.setText(R.id.edit_9, TextUtils.isEmpty(s.getREnergy9()) ? "" : s.getREnergy9());
        baseViewHolder.setText(R.id.edit_10, TextUtils.isEmpty(s.getREnergy10()) ? "" : s.getREnergy10());
        baseViewHolder.setText(R.id.edit_11, TextUtils.isEmpty(s.getREnergy11()) ? "" : s.getREnergy11());
        baseViewHolder.setText(R.id.edit_12, TextUtils.isEmpty(s.getREnergy12()) ? "" : s.getREnergy12());
        baseViewHolder.setText(R.id.edit_13, TextUtils.isEmpty(s.getREnergy13()) ? "" : s.getREnergy13());
        baseViewHolder.setText(R.id.edit_14, TextUtils.isEmpty(s.getREnergy14()) ? "" : s.getREnergy14());
        baseViewHolder.setText(R.id.edit_15, TextUtils.isEmpty(s.getREnergy15()) ? "" : s.getREnergy15());
        baseViewHolder.setText(R.id.edit_16, TextUtils.isEmpty(s.getREnergy16()) ? "" : s.getREnergy16());
        baseViewHolder.setText(R.id.edit_17, TextUtils.isEmpty(s.getREnergy17()) ? "" : s.getREnergy17());
        baseViewHolder.setText(R.id.edit_18, TextUtils.isEmpty(s.getREnergy18()) ? "" : s.getREnergy18());
        baseViewHolder.setText(R.id.edit_19, TextUtils.isEmpty(s.getREnergy19()) ? "" : s.getREnergy19());
        baseViewHolder.setText(R.id.edit_20, TextUtils.isEmpty(s.getREnergy20()) ? "" : s.getREnergy20());
        baseViewHolder.setText(R.id.edit_21, TextUtils.isEmpty(s.getREnergy21()) ? "" : s.getREnergy21());
        baseViewHolder.setText(R.id.edit_22, TextUtils.isEmpty(s.getREnergy22()) ? "" : s.getREnergy22());
        baseViewHolder.setText(R.id.edit_23, TextUtils.isEmpty(s.getREnergy23()) ? "" : s.getREnergy23());
        baseViewHolder.setText(R.id.edit_24, TextUtils.isEmpty(s.getREnergy24()) ? "" : s.getREnergy24());

        ((EditText) baseViewHolder.getView(R.id.edit_1)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy1(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_2)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy2(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));

//                baseViewHolder.setText(R.id.edit_2,editable.toString());
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_3)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy3(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });

        ((EditText) baseViewHolder.getView(R.id.edit_4)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy4(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_5)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy5(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_6)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy6(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_7)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy7(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_8)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy8(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_9)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy9(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_10)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy10(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_11)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy11(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_12)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy12(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_13)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy13(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_14)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy14(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_15)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy15(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_16)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy16(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_17)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy17(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_18)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy18(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_19)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy19(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_20)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy20(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_21)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy21(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_22)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy22(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_23)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy23(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
        ((EditText) baseViewHolder.getView(R.id.edit_24)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                s.setREnergy24(editable.toString());
                baseViewHolder.setText(R.id.total_pow_txt,gettotalPowNum(s));
                total.put(s.getMonthDate(),gettotalPowNum(s));
//                if(mOnItemClickListener!=null){
//                    mOnItemClickListener.OnEditChangeListener(getItemPosition(s),1,editable.toString());
//                }
            }
        });
    }

    private String gettotalPowNum(PowMonth s) {
        double totalPow=0.0;
        double REnergy1=0.0;
        double REnergy2=0.0;
        double REnergy3=0.0;
        double REnergy4=0.0;
        double REnergy5=0.0;
        double REnergy6=0.0;
        double REnergy7=0.0;
        double REnergy8=0.0;
        double REnergy9=0.0;
        double REnergy10=0.0;
        double REnergy11=0.0;
        double REnergy12=0.0;
        double REnergy13=0.0;
        double REnergy14=0.0;
        double REnergy15=0.0;
        double REnergy16=0.0;
        double REnergy17=0.0;
        double REnergy18=0.0;
        double REnergy19=0.0;
        double REnergy20=0.0;
        double REnergy21=0.0;
        double REnergy22=0.0;
        double REnergy23=0.0;
        double REnergy24=0.0;
        if(!TextUtils.isEmpty(s.getREnergy1())){
            REnergy1 = Double.valueOf(s.getREnergy1());
        }
        if(!TextUtils.isEmpty(s.getREnergy2())){
            REnergy2 = Double.valueOf(s.getREnergy2());
        }

        if(!TextUtils.isEmpty(s.getREnergy3())){
            REnergy3 = Double.valueOf(s.getREnergy3());
        }

        if(!TextUtils.isEmpty(s.getREnergy4())){
            REnergy4 = Double.valueOf(s.getREnergy4());
        }

        if(!TextUtils.isEmpty(s.getREnergy5())){
            REnergy5 = Double.valueOf(s.getREnergy5());
        }

        if(!TextUtils.isEmpty(s.getREnergy6())){
            REnergy6 = Double.valueOf(s.getREnergy6());
        }
        if(!TextUtils.isEmpty(s.getREnergy7())){
            REnergy7 = Double.valueOf(s.getREnergy7());
        }
        if(!TextUtils.isEmpty(s.getREnergy8())){
            REnergy8 = Double.valueOf(s.getREnergy8());
        }

        if(!TextUtils.isEmpty(s.getREnergy9())){
            REnergy9 = Double.valueOf(s.getREnergy9());
        }

        if(!TextUtils.isEmpty(s.getREnergy10())){
            REnergy10 = Double.valueOf(s.getREnergy10());
        }

        if(!TextUtils.isEmpty(s.getREnergy11())){
            REnergy11 = Double.valueOf(s.getREnergy11());
        }

        if(!TextUtils.isEmpty(s.getREnergy12())){
            REnergy12 = Double.valueOf(s.getREnergy12());
        }

        if(!TextUtils.isEmpty(s.getREnergy13())){
            REnergy13 = Double.valueOf(s.getREnergy13());
        }

        if(!TextUtils.isEmpty(s.getREnergy14())){
            REnergy14 = Double.valueOf(s.getREnergy14());
        }

        if(!TextUtils.isEmpty(s.getREnergy15())){
            REnergy15 = Double.valueOf(s.getREnergy15());
        }
        if(!TextUtils.isEmpty(s.getREnergy16())){
            REnergy16 = Double.valueOf(s.getREnergy16());
        }
        if(!TextUtils.isEmpty(s.getREnergy17())){
            REnergy17 = Double.valueOf(s.getREnergy17());
        }

        if(!TextUtils.isEmpty(s.getREnergy18())){
            REnergy18 = Double.valueOf(s.getREnergy18());
        }

        if(!TextUtils.isEmpty(s.getREnergy19())){
            REnergy19 = Double.valueOf(s.getREnergy19());
        }

        if(!TextUtils.isEmpty(s.getREnergy20())){
            REnergy20 = Double.valueOf(s.getREnergy20());
        }

        if(!TextUtils.isEmpty(s.getREnergy21())){
            REnergy21 = Double.valueOf(s.getREnergy21());
        }

        if(!TextUtils.isEmpty(s.getREnergy22())){
            REnergy22 = Double.valueOf(s.getREnergy22());
        }

        if(!TextUtils.isEmpty(s.getREnergy23())){
            REnergy23 = Double.valueOf(s.getREnergy23());
        }
        if(!TextUtils.isEmpty(s.getREnergy24())){
            REnergy24 = Double.valueOf(s.getREnergy24());
        }

        totalPow=REnergy1+REnergy2+REnergy3+REnergy4+REnergy5+REnergy6+REnergy7+REnergy8
                +REnergy9+REnergy10+REnergy11+REnergy12+REnergy13+REnergy14+REnergy15+REnergy16
                +REnergy17+REnergy18+REnergy19+REnergy20+REnergy21+REnergy22+REnergy23+REnergy24;
        return setDouleLenth(totalPow);
    }


    private  String setDouleLenth(double totalNum) {
        BigDecimal two = new BigDecimal(totalNum);
        return   two.setScale(3, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString();
    }
}
